﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Services;
using System.Xml;

using System.Web.Script.Services;

namespace parking
{
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://spartansparking.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        

        
        public string HelloWorld()
        {
            return "Hello World";
        }


        //DT
        [WebMethod(EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public Boolean login(string email, string password)
        {
            return AccountImpl.login(email, password);
        }

        //DT
        [WebMethod(EnableSession = true)]
        public Boolean logout(string email)
        {
            return AccountImpl.logout(email);
        }



        [WebMethod]
        public int createAccount(string email, string password, int accountType, string firstName, string lastName, string address, string city, string state, string zip)
        {

            //return the account id
            return AccountImpl.createAccount(email, password, accountType, firstName, lastName, address, city, state, zip);
            
            //return 123456;
        }

        [WebMethod]
        public int getAccountTypeByEmail(string email)
        {
            //return the account type
            return AccountImpl.getAccountTypeByEmail(email);
        }

        [WebMethod(EnableSession = true)]
        public string getAccountDetails(int userId)
        {

            return AccountImpl.getAccountDetails(userId);

            /*
            return "<account id='123456'>" +
                       "<email>john@doe.com</email>" +
                       "<accounttype>1</accounttype>" +
                       "<firstname>john</firstname>" +
                       "<lastname>doe</lastname>" +
                       "<address>123 acme dr</address>" +
                       "<city>san jose</city>" +
                       "<state>ca</state>" +
                       "<zip>95051</zip>" +
                   "</account>";
             */
        }


        [WebMethod]
        public string getGarageList()
        {

            return GarageImpl.getGarageList();


            /*
            return "<garages>" +
                        "<garage id=1 name='South Garage' address='100 acme dr' city='san jose' state='ca' zip='95052'/>" +
                        "<garage id=2 name='West Garage' address='200 acme dr' city='san jose' state='ca' zip='95052'/>" +
                        "<garage id=3 name='North Garage' address='300 acme dr' city='san jose' state='ca' zip='95052'/>" +
                   "</garages>";
             */
        }

        [WebMethod]
        public int getFloorCount(int garageId)
        {

            return GarageImpl.getFloorCount(garageId);

            //return 5;
        }

        [WebMethod]
        public string getSpotList(int garageId, int floor)
        {

            return GarageImpl.getSpotList(garageId, floor);

            //spot numbering convention: garage id + floor + spot id (e.g. 1203 means garage #1, 2nd floor, spot #03)
            /*
            return "<garage id=1 name='South Garage' address='100 acme dr' city='san jose' state='ca' zip='95052'>" + 
                        "<floor number='1'>" + 
                            "<spot id='1101'/>" + 
                            "<spot id='1102'/>" + 
                            "<spot id='1103'/>" + 
                        "</floor>" + 
                    "</garage>";
             */
        }


        [WebMethod]
        public string getAvailableGarage(string starttime, string endtime)
        {
            //returns only garages that are not full in particular time frame

            return GarageImpl.getAvailableGarage(starttime, endtime);

            /*
            return "<garages>" +
                        "<garage id=1 name='South Garage' address='100 acme dr' city='san jose' state='ca' zip='95052'/>" +
                        "<garage id=3 name='North Garage' address='300 acme dr' city='san jose' state='ca' zip='95052'/>" +
                   "</garages>";

             */
        }

        [WebMethod]
        public string getAvailableSpot(string starttime, string endtime, int garageId)
        {
            //returns only open spots in particular time frame
            return GarageImpl.getAvailableSpot(starttime, endtime, garageId);



            /*
            return "<garage id=1 name='South Garage' address='100 acme dr' city='san jose' state='ca' zip='95052'>" +
                        "<floor number='1'>" +
                            "<spot id='1101' status='available'/>" +
                            "<spot id='1103' status='available'/>" +
                        "</floor>" +
                    "</garage>";
             */
        }

        [WebMethod]
        public string getAvailableSpotByFloor(string starttime, string endtime, int garageId, int floor)
        {
            //returns only open spots in particular time frame
            return GarageImpl.getAvailableSpotByFloor(starttime, endtime, garageId, floor);
        }

        [WebMethod]
        public string getAvailableSpotByUserType(string starttime, string endtime, int garageId, int userType)
        {
            //returns only open spots in particular time frame
            return GarageImpl.getAvailableSpotByUserType(starttime, endtime, garageId, userType);

        }

        [WebMethod]
        public string getAvailableSpotByFloorAndUserType(string starttime, string endtime, int garageId, int floor, int userType)
        {
            //returns only open spots in particular time frame
            return GarageImpl.getAvailableSpotByFloorAndUserType(starttime, endtime, garageId, floor, userType);

        }


        [WebMethod]
        public string getSpotListByTime(string starttime, string endtime, int garageId, int floor)
        {

            //returns all spots, but with its status in a specific timeframe
            return "<garage id=1 name='South Garage' address='100 acme dr' city='san jose' state='ca' zip='95052'>" +
                        "<floor number='1'>" +
                            "<spot id='1101' status='available'/>" +
                            "<spot id='1102' status='available'/>" +
                            "<spot id='1103' status='available'/>" +
                        "</floor>" +
                    "</garage>";
        }

        [WebMethod(EnableSession = true)]
        public int reserveSpot(string email, string starttime, string endtime, int spotId)
        {
            //return reservation id
            return ReservationImpl.reserveSpot(email, starttime, endtime, spotId);

            //return 222333;
        }

        [WebMethod(EnableSession = true)]
        public string getReservationDetails(int reservationId)
        {
            return ReservationImpl.getReservationDetails(reservationId);
            
            /*
            return "<reservation id='222333'>" + 
                       "<accountid>123456</accountid>" +
                       "<email>john@doe.com</email>" +
                       "<starttime>04/06/13 8:00</starttime>" + 
                       "<endtime>04/06/13 13:00</endtime>" +
                       "<spotId>1103</spotId>" +
                       "<totaldue>30.00</totaldue>" + //total $$ due for visitor, otherwise will be 0.00
                   "</reservation>";
             */
        }

        [WebMethod(EnableSession = true)]
        public string getReservationByEmail(string email)
        {
            return ReservationImpl.getReservationByEmail(email);

            /*
            return "<reservation id='222333'>" + 
                       "<accountid>123456</accountid>" +
                       "<email>john@doe.com</email>" +
                       "<starttime>04/06/13 8:00</starttime>" + 
                       "<endtime>04/06/13 13:00</endtime>" +
                       "<spotId>1103</spotId>" +
                       "<totaldue>30.00</totaldue>" + //total $$ due for visitor, otherwise will be 0.00
                   "</reservation>";
             */
        }


        //DT
        [WebMethod(EnableSession = true)]
        public Boolean cancelReservation(int reservationId) //Change the paramater type from String to int
        {
            return ReservationImpl.cancelReservation(reservationId);
            //return true;
        }

        [WebMethod(EnableSession = true)]
        public Boolean blockSpot(int spotId)
        {
            return AdminImpl.blockSpot(spotId);

            //return true;
        }

        [WebMethod(EnableSession = true)]
        public Boolean unblockSpot(int spotId)
        {
            return AdminImpl.unblockSpot(spotId);

            //return true;
        }

        [WebMethod(EnableSession = true)]
        public String getAllReservationList()
        {
            return ReservationImpl.getAllReservationList();
            //return true;
        }


    }
}
